
import 'dart:io';

import 'package:demo/pages/Home.dart';
import 'package:demo/pages/Me.dart';
import 'package:demo/pages/webview.dart';
import 'package:demo/pages/webview2.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';


class Layout extends StatefulWidget{
  const Layout({Key?key}):super(key:key);
  @override
  State<Layout>createState()=>_Layout();

}


class _Layout extends State<Layout> {

  late SystemUiOverlayStyle systemUiOverlayStyle;

  SystemUiOverlayStyle setAndroidSystemBar() {
    systemUiOverlayStyle = SystemUiOverlayStyle();
    try{
      if (Platform.isAndroid) {
        // 设置android状态栏为透明
        // MaterialApp组件会覆盖掉这个值。
        systemUiOverlayStyle = const SystemUiOverlayStyle(
            statusBarColor: Colors.transparent,
            statusBarIconBrightness: Brightness.dark);
        // SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
      }else{
        if(Platform.isIOS){
          systemUiOverlayStyle = SystemUiOverlayStyle.dark;
        }

      }
    }catch(e){

    }

    return systemUiOverlayStyle;
  }
  int currentIndex = 0;
  final PageController _pageController = PageController();



  @override
  Widget build(BuildContext context) {
    // TODO: implement build
   return AnnotatedRegion(value:setAndroidSystemBar(),child:Material(child:Scaffold(
       // appBar:AppBar(
       //    title:Text("首页"),
       //    shadowColor:Colors.transparent,
       //
       // ),
       bottomNavigationBar:Theme(data:Theme.of(context).copyWith(
         highlightColor:Colors.transparent,
         splashColor:Colors.transparent
       ), child: BottomNavigationBar(
         onTap:(index){
           print(index);
           setState(() {
             _pageController.jumpToPage(index);
             currentIndex=index;
           });
         },
         enableFeedback:false,
         currentIndex:currentIndex,
         type:BottomNavigationBarType.fixed,
         iconSize:24,
         unselectedFontSize:10,
         selectedFontSize:10,
         selectedLabelStyle:TextStyle(
             fontWeight:FontWeight.bold
         ),
         selectedItemColor:Colors.blueAccent,
         items:const [
           // TabBarItem(icon:Image(
           //   image:AssetImage("images/bottom_nav_icons/home.png"),
           //   width:24,
           //   height:24,
           // ),label:'123123'),
           BottomNavigationBarItem(icon:Image(
             image:AssetImage("images/bottom_nav_icons/home.png"),
             width:24,
             height:24,
           ),
               activeIcon:Image(
                 image:AssetImage("images/bottom_nav_icons/home_active.png"),
                 width:24,
                 height:24,
               ),
               label:'首页'),
           BottomNavigationBarItem(
               icon:Image(
                 image:AssetImage("images/bottom_nav_icons/todo.png"),
                 width:24,
                 height:24,
               ),
               activeIcon:Image(
                 image:AssetImage("images/bottom_nav_icons/todo_active.png"),
                 width:24,
                 height:24,
               ),label:'待办事项'),
           BottomNavigationBarItem(
               icon:Image(
                 image:AssetImage("images/bottom_nav_icons/chat.png"),
                 width:24,
                 height:24,
               ),
               activeIcon:Image(
                 image:AssetImage("images/bottom_nav_icons/chat_active.png"),
                 width:24,
                 height:24,
               ),
               label:'消息'),
           BottomNavigationBarItem(
               icon:Image(
                 image:AssetImage("images/bottom_nav_icons/contacts.png"),
                 width:24,
                 height:24,
               ),
               activeIcon:Image(
                 image:AssetImage("images/bottom_nav_icons/contacts_active.png"),
                 width:24,
                 height:24,
               ),
               label:'通讯录'),
           BottomNavigationBarItem(
               icon:Image(
                 image:AssetImage("images/bottom_nav_icons/me.png"),
                 width:24,
                 height:24,
               ),
               activeIcon:Image(
                 image:AssetImage("images/bottom_nav_icons/me_active.png"),
                 width:24,
                 height:24,
               ),
               label:'我的')
         ],
       )),
       body:PageView(
         controller: _pageController,
         physics:NeverScrollableScrollPhysics(),
         onPageChanged:(index){
         },
         children: const [
             Home(),
             Center(
                child:Text("待办"),
              ),
             Center(
               child:Text("消息"),
             ),
             Webpage2(),
             Me()

         ],
       )
   )));

  }


}

